The following table shows the variations possible in expressions containing array and scalar subscripts. The result of the assignment operation depends upon the dimensionality of the subscript.
Note: A subscript structure can also be composed of a range of elements. If expression is scalar, it is inserted into the subarray. If Variable[Range] and Array are the same size, elements of Array specified by Range are inserted in Variable. It is illegal if Variable[Range] and Array are different sizes. See Array Subscript Ranges for complete details. For information on when you should not use subscript ranges, see Avoid Using Range Subscripts for Assignment .
Syntax Structure |
Description |
Variable[ScalarSubscripts] = ScalarExpression
|
Expression is stored in a single element of Variable. arrOne = [1, 2, 3, 4, 5] arrOne[2] = 9 PRINT, arrOne 1 2 9 4 5 |
Variable[ScalarSubscripts] = ArrayExpression
|
Expression array is inserted in Variable array beginning at point indicated by subscript. arrOne = [1, 2, 3, 4, 5] arrTwo = [11, 12] arrOne[1] = ArrTwo PRINT, arrOne 1 11 12 4 5 Note: An “out of range subscript” error will occur if you attempt to insert arrTwo elements into non-existent elements of arrOne. For example arrOne[4] = ArrTwo fails. |
Variable[ArraySubscripts] = ScalarExpression
|
Expression scalar is stored in designated elements of Variable. Other array elements are unchanged. arrOne = [1, 2, 3, 4, 5] arrOne[[2, 4]] = 0 PRINT, arrOne 1 2 0 4 0 Note: Note the use of the double brackets. Attempting to assign zeros to the 3rd and 5th element of the array using |
Variable[ArraySubscripts] = ArrayExpression
|
Elements of Expression are stored in designated elements of Variable. arrOne = [1, 2, 3, 4, 5] arrOne[[0, 2]] = [111,333] PRINT, arrOne 111 2 333 4 5 Note: Elements of the subscript array that are negative, or greater than the highest subscript of the subscripted array, are clipped to the target array boundaries. For example, |